package com.zjbd.douyangfile.controller;


import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.zjbd.douyangcommoncore.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.dromara.x.file.storage.core.FileInfo;
import org.dromara.x.file.storage.core.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 抖阳视频上传接口
 */
@Tag(name = "抖阳视频上传接口")
@Slf4j
@RequestMapping("/douyang/file")
@RestController
public class DyVideoFileController {

    //注入实列
    @Autowired
    private FileStorageService fileStorageService;

    @Operation(summary = "上传视频")
    @PostMapping("/uploadVideo")
    public Result uploadVideo(MultipartFile file){
        //当前日期字符串，格式：yyyy-MM-dd
        //String today= DateUtil.today();
        //UUID生成一个随机字符串
        String simpleUUID = IdUtil.simpleUUID();

        FileInfo fileInfo = fileStorageService.of(file)
                .setPath("uploadVideo/") //保存到相对路径下，为了方便管理，不需要可以不写
                .setObjectId(simpleUUID)
                .upload();  //将文件上传到对应地方

        //把上传结果丢到redis里面去


        return Result.success(fileInfo);
    }

}
